package com.zsj;

import java.util.*;

/**
 * @authoer zsj
 * @date 2022/6/9 15:29
 */
public class GAME {
    public static void main(String[] args) {
        Random random = new Random();
        int[] arr = new int[100];
        Map<Integer, Integer> result = new HashMap<>();
        for (int i = 0; i < 10000; i++) {
            int index = 1 + random.nextInt(99);
            arr[index]++;
        }
        for (int i = 1; i < arr.length; i++) {
            result.put(i, arr[i]);
        }
        List<Map.Entry<Integer, Integer>> list = new ArrayList<>(result.entrySet());
        list.sort(new Comparator<Map.Entry<Integer, Integer>>() {
            @Override
            public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {
                return o2.getValue().compareTo(o1.getValue());
            }
        });
        Iterator<Map.Entry<Integer, Integer>> iterator = list.iterator();
        while (iterator.hasNext()) {
            Map.Entry<Integer, Integer> next = iterator.next();
            System.out.println(next.getKey() + ":出现了" + next.getValue() + "次");
        }
    }

}
